package io.kiki.sba.registry.store.jdbc.repository.impl;

import io.kiki.sba.registry.common.model.elector.Lock;
import io.kiki.sba.registry.store.api.config.DefaultCommonConfig;
import io.kiki.sba.registry.store.api.elector.LockRepository;
import io.kiki.sba.registry.store.api.meta.RecoverConfig;
import io.kiki.sba.registry.store.jdbc.constant.TableEnum;
import io.kiki.sba.registry.store.jdbc.mapper.LockMapper;
import org.springframework.beans.factory.annotation.Autowired;


public class LockJdbcRepository implements LockRepository, RecoverConfig {

    @Autowired
    LockMapper lockMapper;

    @Autowired
    DefaultCommonConfig defaultCommonConfig;

    @Override
    public Lock queryDistLock(String lockName) {
        return lockMapper.queryLock(defaultCommonConfig.getClusterId(tableName()), lockName);
    }

    @Override
    public String tableName() {
        return TableEnum.distribute_lock.getTableName();
    }
}
